Ext.define('js.system.EngineeringAddPage', {
    extend: 'Ext.form.Panel',
    requires: ['js.Util', 'js.ctrl.Common'],
    controller: 'Common',
    config: {
        bodyPadding: '0 20 0 20',
        layout: {
            type: 'vbox',
            align: 'stretch'
        }
    },
    hidenField: {
        region_id: undefined
    },
    fieldDefaults: {
        labelWidth:100,
        flex:1,
        xtype: 'panel',
        allowBlank: false
    },
    url: 'structureRoutes',
    initComponent: function () {

        let departmentId = Ext.create('Ext.form.field.Hidden', {
            name: 'structure_id',
        });

        let departmentName = Ext.create('Ext.form.field.Text', {
            name: 'structure_name',
            width:'100%',
            height: 36,
            margin:'30 20 10 20',
            allowBlank: false,
            fieldLabel: '结构名称',
        });
        let sfqy={
            xtype: 'combobox',
            allowBlank: false,
            height: 36,
            width:'100%',
            name:'enable',
            margin:'10 20 10 20',
            fieldLabel: '是否启用',
            triggerAction: 'all',
            editable: false,
            value:1,
            displayField: 'dataType',
            valueField: 'value',
            store: [
                {value: 1, dataType: '是'},
                {value: 2, dataType: '否'},
            ],
        }



   /*     let rowOne = {
            layout: 'vbox',
            items: [departmentId,departmentName,sfqy]
        };*/

        this.buttons = [{
            text: '保存', handler: () => {
                this.submit();
            },
            width:140,
            height:42,
            cls:'btnSubmit',
            margin:'0 20 0 0',
            scope: this
        }];

        this.items = [departmentId,departmentName,sfqy];
        this.getValues = function () {

            return {
                department_id: departmentId.getValue(),
                department_name: departmentName.getValue(),
            };
        };

        this.setValues = function (values) {
            let form = this.getForm();
            form.setValues(values);

        };

        this.submit = function () {
            let form = this.getForm();
            let params = this.getValues();
            params.action_type = departmentId.getValue() ? 'structureUpdate' : 'structureAdd';
            form.submit({params: params, waitMsg: '正在保存...'});
        };

        this.on('actioncomplete', this.success, this)
            .on('actionfailed', this.fail, this);
        this.callParent(arguments);
    },
    success: function (response) {
        Ext.toast(`保存成功`);
        this.up('window').close();
        Ext.getCmp('EngineeringStructureTypeShowPage').getStore().reload();
        let aa=Ext.getCmp('EngineeringStructureTypeShowPage');
    },
    fail: function (form, action) {
        let msg = '';
        if (action.failureType === 'client') {
            msg = '请填写必填项';
        } else if (action.failureType === 'connect') {
            msg = '与服务器失去连接';
        } else if (action.failureType === 'server') {
            msg = action.result.message || '服务器错误';
        } else {
            msg = '未知错误';
        }
        Ext.toast(`保存失败，${msg}`);
    }
});